#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e4 + 5;
const int M = 1e5 + 5;

int n, m;
struct Node {
  int u, v, w;
  bool operator<(Node x) const { return w < x.w; }
} a[M];
int f[N], d[N];
void init() { rep(i, 1, n) f[i] = i, d[i] = 0; }
int find(int x) {
  if (f[x] == x) return x;
  int y = f[x];
  f[x] = find(f[x]);
  d[x] = (d[x] + d[y]) % 2;
  return f[x];
}
bool merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return d[x] != d[y];
  f[fy] = fx, d[fy] = d[x] == d[y] ? 1 : 0;
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) cin >> a[i].u >> a[i].v >> a[i].w;
  sort(a + 1, a + m + 1);
  int ans = 0;
  init();
  per(i, m, 1) {
    if (!merge(a[i].u, a[i].v)) {
      ans = a[i].w;
      break;
    }
  }
  cout << ans;
  return 0;
}